package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/10/23
 * @description
 */
@RestController
@RequestMapping("cities")
public class CityController {

    @Resource
    private CityService cityService;

    @GetMapping
    public List<City> cityList(){
        return cityService.list();
    }


    @GetMapping("{id}")
    public City getOneCity(@PathVariable("id") Integer id){
        return cityService.getById(id);
    }

    @PostMapping
    public City addCity(@RequestBody  City city){
        // 保存城市信息
        cityService.save(city);
        return city;
    }
}
